package com.woniuxy;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.FileSystemResource;

public class TestIoc {

    public static void main(String[] args) {
        //FileSystemResource  通过绝对路劲进行加载
//        BeanFactory beanFactory=new XmlBeanFactory(new FileSystemResource("D:\\085_porejct3\\Java85classcode\\Day02_Spring_IOC\\src\\applicationContext.xml"));
//
//        //ClassPathResource   通过项目相对路劲进行加载
//        BeanFactory beanFactory1=new XmlBeanFactory(new ClassPathResource("applicationContext.xml"));


//      BeanFactory -->泛型:所存的class对象
//        Person jap1 = beanFactory.getBean("jap", Person.class);
//        Person jap2 = beanFactory.getBean("jap", Person.class);
//        System.out.println(jap1);
//        System.out.println(jap2);

        //通过绝对路径获取配置文件 FileSystemXmlApplicationContext 同理
//        ApplicationContext applicationContext = new FileSystemXmlApplicationContext("C:\\Users\\ASUS\\Desktop\\85期的笔记\\java85classcode\\day02ioc\\src\\applicationContext.xml");


        // 通过项目路径找配置文件 ClassPathXmlApplicationContext
//        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");



//        Person jap = applicationContext.getBean("jap", Person.class);
//        System.out.println(jap);
//        jap.run();


        ApplicationContext applicationContext=new ClassPathXmlApplicationContext("applicationContext.xml");
        Person person=(Person) applicationContext.getBean("chinese");
        System.out.println(person);

        ApplicationContext applicationContext1=new ClassPathXmlApplicationContext("applicationContext1.xml");
        Person person1=(Person) applicationContext1.getBean("chinese");
        System.out.println(person1);

    }
}
